<!DOCTYPE html>
<html>
  <head>
    <!--META-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.75">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <!--CSS-->
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.structure.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.theme.min.css" />
    <link rel="stylesheet" href="API/css/mycss.css" />
    <link rel="stylesheet" href="API_RH/css/mycss.css" />
    <link rel="stylesheet" href="css/mycss.css" />

    <!--JS-->
    <script type="text/javascript" src="API/js/jquery.min.js"></script>
    <script type="text/javascript" src="API/js/jquery.mobile.min.js"></script>
    <!--<script type="text/javascript" src="API/js/highcharts.js"></script>-->
    <!--<script type="text/javascript" src="API/js/modules/exporting.js"></script>-->
    <!--<script type="text/javascript" src="API/js/jquery.dataTables.min.js"></script>--> 
    <script type="text/javascript" src="include/config.js"></script>
    <script type="text/javascript" src="API/js/fonctions.js"></script>
    <script type="text/javascript" src="API_RH/js/fonctions.js"></script>
    <script type="text/javascript" src="js/fonctions.js"></script>
	
    <script language="javascript" type="text/javascript">
    checkMaintenance();
    checkAuthentification();
	
    ///////////////////
    //BLOCK VARIABLE GLOBAL
    ///////////////////
    var id_page = 14;
    var WorkerMailSD;
    var data_loading = "";
    var data_decode = {};

    ///////////////////
    //BLOCK FONCTIONS EVENEMENTS
    ///////////////////
		
    /**
     * A la construction de la page
     */
    $(document).on('pageinit',function() {
        try {
            // Init commun
            init_commun();

            // Init page
            afficheAvert();
            afficheRapport();
            afficheListDiffusion();
        }
        catch (er) {
            log(0, "ERROR(init_rapports_admin):" + er.message);
        }
    });
		
    /**
     *  Affichage de la page avant onload
     */
    $(document).on('pageshow',function() {
        try {
            show_commun();
        }
        catch (er) {
            log(0, "ERROR(show):" + er.message);
        }
    });
    
    /**
     * Fin chargement page
     *
     */    
    function OnLoad() {
        try {
            //
            
        }
        catch (er) {
            log(0, "ERROR(OnLoad):" + er.message);
        }
    }
		
		
    ///////////////////
    //BLOCK FONCTIONS METIER
    ///////////////////
    function afficheAvert() {
        try {
            var html = "";

            var labDate = getParameter("last_scan_inventaire_live");

            html += "<br>";
            html += "[ODA]Tickets non affect&eacute;s en priorit&eacute; P1 ou P2, relev&eacute; au "+labDate+".";
            html += "<br>";
            html += "<br>";

            var tabAvert = getTabAvert();

            html += getHtmlAvert(tabAvert);

            html += "<br>";

            $("#div_avert").html(html);
        }
        catch (er) {
            log(0, "ERROR(afficheAvert):" + er.message);
        }
    }
		
    function afficheRapport() {
        try {
            var html = "";

            var labDate = getStrDateFR();

            html += "<br>";
            html += "[ODA]Rapports du "+labDate+".";
            html += "<br>";
            html += "<br>";

            html += "<p>Liste des tickets P1 & P2 qui expireront aujourd'hui : </p>";

            var tabExpireToday = new Array();
            tabExpireToday = getExpireToday();

            innerHtmlExpireToday = getHTMLExpireToday(tabExpireToday);

            html += innerHtmlExpireToday;

            html += "<p>Liste des tickets P3 & P4 qui expireront aujourd'hui : </p>";

            var tabExpire20h = new Array();
            tabExpire20h = getExpire20h();

            innerHtmlExpire20h = getHTMLExpire20h(tabExpire20h);

            html += innerHtmlExpire20h;

            var htmlTab5 = "";
            var tabResultatTab5 = new Array();

            tabResultatTab5 = gettabResultatTab5();

            htmlTab5 = getHTMLTab5(tabResultatTab5);

            html += htmlTab5;

            $("#div_rapports").html(html);
        }
        catch (er) {
            log(0, "ERROR(afficheAvert):" + er.message);
        }
    }

    /**
     * Affiche la liste de diffusion pour le site
     * 
     */
    function afficheListDiffusion() {
        try {
            var tabListDiffusion = new Array();
            
            var tabInput = {};

            tabListDiffusion = callBD("phpsql/mysql_getListDiffusion.php", "GET", "text", tabInput, "", false);
            
            var html = getHtmlListDiffusion(tabListDiffusion);
            $("#div_listDiffusion").html(html);
        }
        catch (er) {
            log(0, "ERROR(afficheAvert):" + er.message);
        }
    }
    
    /**
     * Decode un msg en ligne avec un CI.
     * 
     */
    function traitementDecodeMsg() {
        try {
            if (window.File && window.FileReader && window.FileList && window.Blob) {
                var CIJson = JSON.parse(data_decode["file_ci"]);
                var datas = data_decode["file_data"];
                var tempTab = datas.split("\n");

                var resultats = {};

                for (var indice in tempTab) {
                    var resultat = {};
                    var typeLigne = tempTab[indice].substr(0,2);
                    for (var attr in CIJson[typeLigne]){
                        var obligatoire = CIJson[typeLigne][attr]["obligatoire"];
                        var position = CIJson[typeLigne][attr]["position"];
                        var longueur = CIJson[typeLigne][attr]["longueur"];
                        var format = CIJson[typeLigne][attr]["format"];
                        var valeur = tempTab[indice].substr(position,longueur);
                        if(format == "int"){
                            resultat[attr] = parseInt(valeur);
                        } else if (format == "string") {
                            resultat[attr] = valeur;
                        } else {
                            resultat[attr] = valeur;
                        }

                    }
                    resultats[indice] = resultat;
                }

                var strResultats = JSON.stringify(resultats);

                window.URL = window.URL || window.webkitURL;

                var a = document.createElement('a');
                var blob = new Blob([strResultats], {'type':'application\/octet-stream'});
                a.href = window.URL.createObjectURL(blob);
                a.download = 'resultat_'+getStrDateTimeUSLessSeparator()+'.json';
                a.click();
            } else {
                notification("notifcation", "Fonction indisponible, pour profiter d'une expérience optimum, merci d'utiliser un navigateur récent.",_WARNING);
            }
        }
        catch (er) {
            log(0, "ERROR(traitementDecodeMsg):" + er.message);
            notification("notifcation", "Erreur : "+er.message,_ALERT);
        }
    }
    
    ///////////////////
    //BLOCK FONCTIONS TECHNIQUES
    ///////////////////
    /**
     * Charge les données du fichier.
     * 
     * @param {JSobj} p_obj_intput
     */
    function readBlob(p_obj_intput) {
        try {
            if (window.File && window.FileReader && window.FileList && window.Blob) {
                var files = p_obj_intput.files;

                if (!files.length) {
                  notification("notifcation", "Merci de choisir un fichier.",_WARNING);
                }else{
                    var file = files[0];

                    data_loading = p_obj_intput.id;

                    var reader = new FileReader();

                    reader.onloadend = function(evt) {
                      if (evt.target.readyState == FileReader.DONE) {
                        var retult = evt.target.result;
                        data_decode[data_loading] = retult;
                      }
                    };

                    reader.readAsBinaryString(file);
                }
            } else {
                notification("notifcation", "Fonction indisponible, pour profiter d'une expérience optimum, merci d'utiliser un navigateur récent.",_WARNING);
            }
        }catch (er) {
            log(0, "ERROR(readBlob):" + er.message);
        }
    }
		
    ///////////////////
    //BLOCK FONCTIONS AFFICHAGE
    ///////////////////

    function getHtmlListDiffusion(p_tabListDiffusion) {
        try {
            var strResponse = "";

            for (var indice in p_tabListDiffusion) {
                strResponse += p_tabListDiffusion[indice][1] + ";<br>";
            }

            return strResponse;
        }
        catch (er) {
            log(0, "ERROR(getHtmlListDiffusion):" + er.message);
        }
    }		
    </script>
	
  </head>
  <body onload="OnLoad();">
    
    <!-- page -->
    <div data-role="page" data-title="Titre">

        <!-- /panel -->
        <div data-role="panel" id="mypanel" data-display="overlay" data-position="left">

        </div>
        <!-- /panel -->

        <!-- header -->
        <div data-role="header" data-position="fixed">
            <a href="#mypanel" data-role="button" data-icon="home" data-iconpos="notext">home</a>
            <h1 id="id_titre">titre</h1>
            <a href="javascript:window.location = ('./page_contact.html?mili='+getMilise());" data-role="button" data-icon="info" data-iconpos="notext">Contact</a>
        </div>
        <!-- /header -->
         
        <!-- navbar -->
        <div data-role="navbar" data-grid="c">
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
                <li><a href="#">Four</a></li>
            </ul>
        </div>
        <!-- /navbar -->

        <!-- content -->
        <div data-role="content" id="main_content">

            <div data-role="collapsible" data-collapsed="true" data-mini="true">
                <h3>Rappels pour les tickets en Support/D&eacute;blocage</h3>
                <a href="javascript:traitementMailSD();" data-role="button" data-inline="true" data-icon="arrow-r" data-mini="true">Lancer traitement</a>
                <div id="div_rappelSupDeb"></div>					
            </div>

            <div data-role="collapsible" data-collapsed="true" data-mini="true">
                <h3>Avertissement P1&P2 non affect&eacute;s</h3>
                <div id="div_avert">Anomalie code E008</div>
                <a href="javascript:envoyerAvert();" data-role="button" data-inline="true" data-icon="arrow-r" data-mini="true">Soumettre</a>					
            </div>

            <div data-role="collapsible" data-collapsed="true" data-mini="true">
                <h3>Rapports journaliers</h3>
                <div id="div_rapports">Anomalie code E010</div>
                <a href="javascript:envoyerRapports();" data-role="button" data-inline="true" data-icon="arrow-r" data-mini="true">Soumettre</a>					
            </div>

            <div data-role="collapsible" data-collapsed="true" data-mini="true">
                <h3>La liste de diffusion</h3>
                <div id="div_listDiffusion">Anomalie code E009</div>
            </div>

            <div data-role="collapsible" data-collapsed="true" data-mini="true">
                <h3>Extraction d'un message</h3>
                <label for="file_ci">Fichier CI:</label>
                <input type="file" name="file_ci" id="file_ci" value="" data-clear-btn="true" onchange="javascript:readBlob(this);" />
                <label for="file_data">Données:</label>
	        <input type="file" name="file_data" id="file_data" value="" data-clear-btn="true" onchange="javascript:readBlob(this);" />
                <a href="javascript:traitementDecodeMsg();" data-role="button" data-inline="true" data-icon="arrow-r" data-mini="true">Lancer traitement</a>
                
                <div id="div_extractMsg">Anomalie code E009</div>
            </div>
            
            <div id="notifcation" style="background-color:#f7931e;position:absolute;bottom:50px;width:97%;text-align:center;vertical-align:middle;line-height:normal;line-height:30px;height:30px;display:none"></div>		
        </div>
        <!-- /content -->

        <!-- footer -->
        <div data-role="footer" data-position="fixed">
            <a data-role="button" data-icon="search" data-iconpos="notext" class="ui-btn-left" href="javascript:window.location = ('./page_faq.html?mili='+getMilise());">FAQ</a>
            <h1 id="id_affichageUser">User</h1>
            <a data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right" href="javascript:window.location = ('./page_sortie.html?mili='+getMilise());">Logout</a>
        </div>
        <!-- /footer -->

    </div>
    <!-- /page -->
</body>
</html>